import $fairCmd from '../util/$faircmd'

// 获取当前登录人信息
export const getbackground = () => {

    let params = {
        url: '/logo/getLogo',
        method: 'POST',
        data:{}
    };

    return $fairCmd(params);
};


export const getRule =()=>{
    let params = {
        url: '/rules/getRule',
        method: 'POST',
        data:{}
    };
    return $fairCmd(params);
}

export const getInfo = (uuid) => {
    let openid = getOpenidHandler(uuid)
    if(openid) {
        var formdata = new FormData();
        formdata.append("uuid", openid)
        let params = {
            url: '/userinfo/info',
            method: 'POST',
            data: formdata
        };
        return $fairCmd(params);
    }
}


export const getRatio = () => {
    let params = {
        url: '/gift/getRatio',
        method: 'POST',
        data:{}
    };
    return $fairCmd(params);
}

export const getPrizeList = (uuid) => {
    let openid = getOpenidHandler(uuid)
    if(openid) {
        var formdata = new FormData();
        formdata.append("uuid", openid)
        let params = {
            url: '/prize/getList',
            method: 'POST',
            data: formdata
        };
        return $fairCmd(params);
    }
}

export const receive = (attr2, name, phone) => {
    var formdata = new FormData();
    formdata.append("attr2", attr2)
    formdata.append("name", name)
    formdata.append("phone", phone)
    let params = {
        url: '/prize/receive',
        method: 'POST',
        data:formdata
    };
    return $fairCmd(params);
}

export const savePrize = (uuid, prize) => {
    let openid = getOpenidHandler(uuid)
    if(openid) {
        var formdata = new FormData();
        formdata.append("uuid", openid)
        // formdata.append("prize_name", prize.name)
        // formdata.append("prize_id", prize.value)
        // formdata.append("prize_levelname", prize.levelname)
        let params = {
            url: '/prize/save',
            method: 'POST',
            data: formdata
        };
        return $fairCmd(params);
    }
}

export const getByAttr2 = (attr2) => {
    var formdata = new FormData();
    formdata.append("attr2", attr2)
    let params = {
        url: '/prize/getByAttr2',
        method: 'POST',
        data:formdata
    };
    return $fairCmd(params);
}

export const saveCode = (uuid, attr2, code) => {
    let openid = getOpenidHandler(uuid)
    if(openid) {
        var formdata = new FormData();
        formdata.append("uuid", openid)
        formdata.append("code", code)
        formdata.append("attr2", attr2)
        let params = {
            url: '/prize/saveCode',
            method: 'POST',
            data: formdata
        };
        return $fairCmd(params);
    }
}

export const getConfig = (url) => {
    var formdata = new FormData();
    formdata.append("url", url)
    let params = {
        url: '/wxconfig/getConfig',
        method: 'POST',
        data:formdata
    };
    return $fairCmd(params);
}
export const share = (uuid, type) => {
    let openid = getOpenidHandler(uuid)
    if(openid) {
        var formdata = new FormData();
        formdata.append("uuid", openid)
        formdata.append("type", type)
        let params = {
            url: '/userinfo/share',
            method: 'POST',
            data: formdata
        };
        return $fairCmd(params);
    }
}

export const savewgnumber = () => {
    let params = {
        url: '/peoplenum/wgadd',
        method: 'POST',
        data:{}
    };
    return $fairCmd(params);
}

export const getOpenid = (code) => {
    var formdata = new FormData();
    formdata.append("uuid", code)
    let params = {
        url: '/userinfo/infoOpenid',
        method: 'POST',
        data: formdata
    };
    return $fairCmd(params);
}

export const saveAppointment = (uuid,name,phone) => {
    let openid = getOpenidHandler(uuid)
    if(openid) {
        var formdata = new FormData();
        formdata.append("openid", openid)
        formdata.append("name", name)
        formdata.append("phone", phone)
        let params = {
            url: '/appointment/saveInfo',
            method: 'POST',
            data: formdata
        };
        return $fairCmd(params);
    }
}

function getOpenidHandler(openid) {
    // let url = "http://3692745so8.51vip.biz/"
    let url = "http://wx.lejuhaofang.net/"
    if(openid){
        return openid
    } else {
        // return  'oQsnG5-0IGILNvqxD_0C2_y-etP8'
        // this.$alert('请在微信内打开', '燕园理想城', {
        //     confirmButtonText: '确定',
        //     callback: action => {
        // window.location.href = url
        //     }
        // });
    }
}
